package org.ahuanlien.crm.service.impl;

import org.ahuanlien.crm.domain.BillRecord;
import org.ahuanlien.crm.mapper.BillRecordMapper;
import org.ahuanlien.crm.query.BillRecordQueryObject;
import org.ahuanlien.crm.query.SalesChartQueryObject;
import org.ahuanlien.crm.service.IBillRecordService;
import org.ahuanlien.crm.util.PageResult;
import org.ahuanlien.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;


@Service
public class BillRecordServiceImpl implements IBillRecordService {
    @Autowired
    BillRecordMapper billRecordMapper;

    public BillRecord getBySn(String sn) {
        return billRecordMapper.getBySn(sn);
    }

    public PageResult query(BillRecordQueryObject qo) {
        int count = billRecordMapper.query4Count(qo);
        if (count == 0) {
            return new PageResult(count, Collections.EMPTY_LIST);
        }
        List<BillRecord> result = billRecordMapper.query4List(qo);
        return new PageResult(count, result);
    }

    public void updateByPrimaryKey(BillRecord billRecord) {
        billRecordMapper.updateByPrimaryKey(billRecord);
    }

    public void insert(BillRecord billRecord) {
        billRecordMapper.insert(billRecord);
    }

    public void deleteByPrimaryKey(Long id) {
        billRecordMapper.deleteByPrimaryKey(id);
    }

    public List<Map<String, BigDecimal>> queryByGroupType(SalesChartQueryObject qo) {
        return billRecordMapper.queryByGroupType(qo);
    }



    /*//缴费
    public void pay(Long id) {
        BillRecord billRecord = billRecordMapper.selectByPrimaryKey(id);
        billRecord.setState("已缴费");
        billRecordMapper.upState(billRecord);

    }*/

    @Override
    public void update(BillRecord billRecord) {
        billRecord.setState("缴费..");
        billRecord.setInputUser(UserContext.getCurrentUser());
        billRecordMapper.update(billRecord);
    }
}
